//
//  AutoMoodView.m
//  WeightMaster
//
//  Created by sungeo on 15/8/25.
//  Copyright (c) 2015年 buddysoft. All rights reserved.
//

#import "AutoMoodView.h"
#import <Masonry.h>
#import <EXTScope.h>

@implementation AutoMoodView

- (instancetype)init{
    if (self = [super init]) {
        _imageView = [[UIImageView alloc] init];
        [self addSubview:_imageView];
        
        _label = [[UILabel alloc] init];
        _label.textAlignment = NSTextAlignmentCenter;
        _label.textColor = [UIColor whiteColor];
        _label.font = [UIFont systemFontOfSize:20.0f];
        [self addSubview:_label];
        
        @weakify(self);
        [_imageView mas_makeConstraints:^(MASConstraintMaker * maker){
            @strongify(self);
            maker.center.equalTo(self);
            maker.width.equalTo(@(125));
            maker.height.equalTo(@(125));
        }];
        
        [_label mas_makeConstraints:^(MASConstraintMaker * maker){
            maker.top.equalTo(_imageView.mas_bottom).offset(8);
            maker.centerX.equalTo(_imageView.mas_centerX);
            maker.bottom.equalTo(self.mas_bottom);
        }];
    }
    
    return self;
}

+ (BOOL)requiresConstraintBasedLayout{
    return YES;
}

- (void)resetContentWithMood:(WMMood)mood{
    WMGender gender = (WMGender)[[WMAppSetting sharedInstance].gender integerValue];
    
    UIImage * image;
    NSString * imageName;
    NSString * text;
    
    switch (mood) {
        case WMMoodHappy:
            imageName = (gender == WMGenderMale) ? @"mood_happy_male" : @"mood_happy_female";
            text = @"不错哦，继续努力吧";
            break;
        case WMMoodUnhappy:
            imageName = (gender == WMGenderMale) ? @"mood_unhappy_male" : @"mood_unhappy_female";
            text = @"好像没什么变化哦，加油！";
            break;
        case WMMoodCry:
            imageName = (gender == WMGenderMale) ? @"mood_cry_male" : @"mood_cry_female";
            text = @"没搞错吧，你行不行啊！";
            break;
    }
    
    image = [UIImage imageNamed:imageName];
    
    _imageView.image = image;
    _label.text = text;
}

@end
